package com.baseframe.auth.granter;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.CompositeTokenGranter;
import org.springframework.security.oauth2.provider.TokenGranter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BaseTokenGranterConfiguration {

    public static TokenGranter getTokenGranters(final AuthenticationManager authenticationManager,final AuthorizationServerEndpointsConfigurer endpoints){
        // 默认tokenGranter集合
        List<TokenGranter> granters = new ArrayList<>(Collections.singletonList(endpoints.getTokenGranter()));
        //验证码
        granters.add(new BaseCaptchaTokenGranter(authenticationManager,endpoints.getTokenServices(),endpoints.getClientDetailsService(),endpoints.getOAuth2RequestFactory()));
        //短信验证码
        granters.add(new BaseSmsTokenGranter(endpoints.getTokenServices(),endpoints.getClientDetailsService(),endpoints.getOAuth2RequestFactory()));

        return new CompositeTokenGranter(granters);
    }
}
